<template>
  <div class="dashboard-layout">
    <!-- 顶部栏 -->
    <header class="top-bar">
      <h1>仪表板</h1>
    </header>

    <div class="main-content">
      <!-- 侧边栏 -->
      <el-menu default-active="1" class="sidebar" @select="handleSelect">
        <!-- 仪表板菜单项（可展开） -->
        <el-sub-menu index="1">
          <template #title>
            <el-icon>
              <DataLine />
            </el-icon>
            <span>仪表板</span>
          </template>
          <el-menu-item index="1-1">概览</el-menu-item>
          <el-menu-item index="1-2">分析</el-menu-item>
          <el-menu-item index="1-3">报告</el-menu-item>
        </el-sub-menu>
        <!-- 个人资料菜单项 -->
        <el-menu-item index="2">
          <el-icon>
            <User />
          </el-icon>
          <span>个人资料</span>
        </el-menu-item>
        <!-- 设置菜单项 -->
        <el-menu-item index="3">
          <el-icon>
            <Setting />
          </el-icon>
          <span>设置</span>
        </el-menu-item>
      </el-menu>

      <!-- 主要内容区域 -->
      <main class="content">
        <component :is="currentComponent"></component>
      </main>
    </div>
  </div>
</template>

<script setup>
import { defineComponent, ref, onMounted, onUnmounted, getCurrentInstance, watch, shallowRef } from 'vue'
import { DataLine, User, Setting } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
import axios from 'axios'
import { ElMessage } from 'element-plus'

import Dashboard from '@/components/MenuItem/Dashboard.vue'
import Profile from '@/components/MenuItem/Profile.vue'
import Settings from '@/components/MenuItem/Settings.vue'

const { appContext } = getCurrentInstance();
const HOST_URL = appContext.config.globalProperties.$HOST_URL
let router = useRouter()
const route = useRoute();
const room_id = route.query.room_id;
const analyzed_date = route.query.analyzed_date;

// 当前显示的组件
const currentComponent = shallowRef(Dashboard)

// 处理菜单选择
const handleSelect = (index) => {
  switch (index) {
    case '1':
    case '1-1':
    case '1-2':
    case '1-3':
      currentComponent.value = Dashboard
      break
    case '2':
      currentComponent.value = Profile
      break
    case '3':
      currentComponent.value = Settings
      break
  }
}

</script>

<style scoped lang="scss">
/* 整体布局样式 */
.dashboard-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* 顶部栏样式 */
.top-bar {
  color: white;
  padding: 0 20px;
  height: 60px;
  /* 适中的高度 */
  display: flex;
  align-items: center;
  /* 设置下边框线 */
  border-bottom: 2px solid #e2e5ee;
}

.top-bar h1 {
  margin: 0;
  font-size: 1.5rem;
}

/* 主要内容区域样式 */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  /* 防止出现滚动条 */
}

/* 侧边栏样式 */
.sidebar {
  width: 200px;
  height: calc(100vh - 60px);
  /* 减去顶部栏的高度 */
  overflow-y: auto;
  /* 允许垂直滚动 */
}

/* 内容区域样式 */
.content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  /* 允许垂直滚动 */
}

/* 确保图标和文字垂直对齐 */
.el-menu-item,
.el-sub-menu__title {
  display: flex;
  align-items: center;
}

.el-icon {
  margin-right: 5px;
}
</style>